package com.genesis.yunnanji.widget;

import android.content.Context;
import android.graphics.Bitmap;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.request.RequestOptions;

import com.genesis.yunnanji.R;
import com.youth.xframe.utils.imageload.ImageLoader;

/**
 * @author: Kite
 * @date: 2018-08-27
 * @description:
 */
public class GlideImageLoader implements ImageLoader {

    private Context mContext;

    public GlideImageLoader(Context mContext) {
        this.mContext = mContext;
    }

    @Override
    public void load(ImageView imageView, Object imageUrl) {
        Glide.with(mContext)
                .load(imageUrl)
                .into(imageView);
    }

    @Override
    public void load(ImageView imageView, Object imageUrl, int defaultImage) {
        RequestOptions options = new RequestOptions()
                .placeholder(defaultImage);
        Glide.with(mContext)
                .load(imageUrl)
                .apply(options)
                .into(imageView);
    }

    @Override
    public void load(ImageView imageView, Object imageUrl, Object transformation) {
        RequestOptions options = new RequestOptions()
                .placeholder(R.mipmap.ic_launcher_round)
                .centerCrop()
                .transform((Transformation<Bitmap>) transformation);
        Glide.with(mContext)
                .load(imageUrl)
                //这里需要强转成当前框架的实现类型，这里是glide举例
                .apply(options)
                .into(imageView);
    }
}
